package com.beiye.drivertransport.fragment;


import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.SubActivity.CourseDetailsActivity;
import com.beiye.drivertransport.adapter.CourseSuperAdatper;
import com.beiye.drivertransport.adapter.PopWindowApt;
import com.beiye.drivertransport.adapter.PopWindowDateApt;
import com.beiye.drivertransport.bean.CheckBean;
import com.beiye.drivertransport.bean.CheckDateBean;
import com.beiye.drivertransport.bean.CourseSuperBean;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.utils.CameraCanUseUtils;
import com.beiye.drivertransport.utils.CustomProgressDialog;
import com.beiye.drivertransport.utils.LogUtils;
import com.beiye.drivertransport.utils.MessageEvent;
import com.beiye.drivertransport.utils.TiShiDialog;
import com.beiye.drivertransport.utils.ToastUtil;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.github.jdsjlzx.interfaces.OnLoadMoreListener;
import com.github.jdsjlzx.interfaces.OnRefreshListener;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;


import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

/**
 * A simple {@link Fragment} subclass.
 */
//课程超市（这种界面暂时没有用到）
public class CourseSupermarketFragment extends TwoBaseFgt {
    private PopWindowApt popWindowApt;
    final private int REQUEST_CODE_ASK_PERMISSIONS = 123;//权限请求码

    private int firstIndex = 1;
    private int pageSize = 10;
    private PopupWindow mPopWindow;

    TextView tv_course;

    View empty_view;

    LRecyclerView lv_course;

    TextView img_coursesupermarket;
    ArrayList<LoginUserBean.DataBean.CurUserOrgBean> cusList = new ArrayList<>();
    private LRecyclerViewAdapter lRecyclerViewAdapter1;
    private CourseSuperAdatper courseSuperAdatper;
    private CustomProgressDialog dialog;
    private PopupWindow mPopWindowDate;
    private PopWindowDateApt popWindowDateApt;


    @Override
    public int getLayoutId() {

        return R.layout.fragment_course_supermarket;

    }

    public void onClick(View view) {

    }

    @Override
    public void initData() {
        tv_course = (TextView) getActivity().findViewById(R.id.tv_course7);
        empty_view = (View) getActivity().findViewById(R.id.empty_view);
        lv_course = (LRecyclerView) getActivity().findViewById(R.id.lv_coursesupermarket);
        img_coursesupermarket = (TextView) getActivity().findViewById(R.id.img_coursesupermarket);

        tv_course.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (popWindowApt == null || popWindowApt.getCount() == 1) {
                    return;
                } else {
                    showPopupWindow();
                }
            }
        });

        //注册EventBus
        EventBus.getDefault().register(this);
        initUi();
        LoginUserBean userInfo = UserManger.getUserInfo();
        initCompany(userInfo);

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(MessageEvent event) {
        LoginUserBean userInfo = event.getUserInfo();
        initCompany(userInfo);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);//反注册EventBus
    }

    private void initCompany(LoginUserBean userInfo) {
        //   LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        LogUtils.e("userId", userId);//6E7119CD-699B-49A2-A0B0-045D0BF7B8C0
        List<LoginUserBean.DataBean.CurUserOrgBean> curuserOrglist = data.getCur_userOrg();
        if (curuserOrglist.size() == 0) {
            img_coursesupermarket.setVisibility(View.INVISIBLE);
            return;
        }
        cusList.clear();
        for (int i = 0; i < curuserOrglist.size(); i++) {
            if (curuserOrglist.get(i).getMark() != 2) {
                cusList.add(curuserOrglist.get(i));
            }
        }
        String orgName = cusList.get(0).getOrgName();
        String orgId = cusList.get(0).getOrgId();
        //   String adId = curuserOrglist.get(0).getAdId();
        int mark = cusList.get(0).getMark();
        int minPer = cusList.get(0).getMinPer();
        int readInterval = cusList.get(0).getReadInterval();
        tv_course.setText(orgName);
        //存储一份readInterval文件
        SharedPreferences sp = getActivity().getSharedPreferences("orgId6",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("orgId", orgId);
        editor.putInt("minPer", minPer);
        editor.commit();
        //存储一份readInterval文件
        SharedPreferences spp = getActivity().getSharedPreferences("readInterval3",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor1 = spp.edit();
        editor1.putInt("readInterval", readInterval);
        editor1.commit();
        SharedPreferences sppp = getActivity().getSharedPreferences("Mark3", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor2 = sppp.edit();
        editor2.putInt("Mark", mark);
        editor2.commit();
        requestData();
        //      readintervalData(adId);
        popWindowApt = new PopWindowApt(getActivity(), cusList, R.layout.popwindow_item_layout);
        if (popWindowApt.getCount() == 1) {
            img_coursesupermarket.setVisibility(View.INVISIBLE);
        } else {
            img_coursesupermarket.setVisibility(View.VISIBLE);
        }


//        OkGo.get(AppInterfaceConfig.BASE_URL + "vehicle/vehicleOrg/" + userId)     // 请求方式和请求url
//                .tag(this)                       // 请求的 tag, 主要用于取消对应的请求
//                .execute(new StringCallback() {
//                    @Override
//                    public void onSuccess(String result, Call call, Response response) {
//
//                        CompanyBean companyBean = JSON.parseObject(result, CompanyBean.class);
//                        List<CompanyBean.RowsBean> rows = companyBean.getRows();
//
//                        if(rows.size()==0)
//                        {
//                            LoginUserBean userInfo = UserManger.getUserInfo();
//                            String orgName = userInfo.getOrgName();
//                            String orgId = userInfo.getOrgId();
//                            CompanyBean.RowsBean temp = new CompanyBean.RowsBean();
//                            temp.setOrgId(userInfo.getOrgId());
//                            temp.setOrgName(userInfo.getOrgName());
//                            rows.add(temp);
//                            tv_course.setText(orgName);
//                            //存储一份readInterval文件
//                            SharedPreferences sp = getActivity().getSharedPreferences("orgId6",
//                                    Context.MODE_PRIVATE);
//                            SharedPreferences.Editor editor = sp.edit();
//                            editor.putString("orgId",orgId);
//                            editor.commit();
//                            requestData();
//                        }else{
//
//                            tv_course.setText(rows.get(0).getOrgName());
//
//                            //存储一份readInterval文件
//                            SharedPreferences sp = getActivity().getSharedPreferences("orgId6",
//                                    Context.MODE_PRIVATE);
//                            SharedPreferences.Editor editor = sp.edit();
//                            editor.putString("orgId", rows.get(0).getOrgId());
//                            editor.commit();
//                            requestData();
//                        }
//                        popWindowApt = new PopWindowApt(getActivity(), rows, R.layout.popwindow_item_layout);
//                    }
//                });

    }

    private void showPopupWindow() {
        //设置contentView
        View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.popwindow_layout, null);
        mPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        //设置各个控件的点击响应
        ListView lv_company = (ListView) contentView.findViewById(R.id.lv_company);
        lv_company.setAdapter(popWindowApt);
        mPopWindow.showAtLocation(tv_course, Gravity.CENTER, 0, 0);
        //     mPopWindow.setAnimationStyle(R.style.contextMenuAnim);
        //    mPopWindow.showAsDropDown(tv_course);
        lv_company.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                if (popWindowApt != null) {

                    String orgName = popWindowApt.getItem(position).getOrgName();
                    String orgId = popWindowApt.getItem(position).getOrgId();
                    //     String adId = popWindowApt.getItem(position).getAdId();
                    int minPer = popWindowApt.getItem(position).getMinPer();
                    int readInterval = popWindowApt.getItem(position).getReadInterval();
                    int mark = popWindowApt.getItem(position).getMark();
                    //存储一份readInterval文件
                    SharedPreferences sp = getActivity().getSharedPreferences("orgId6",
                            Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putString("orgId", orgId);
                    editor.putInt("minPer", minPer);
                    editor.commit();
                    //存储一份readInterval文件
                    SharedPreferences spp = getActivity().getSharedPreferences("readInterval3",
                            Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor1 = spp.edit();
                    editor1.putInt("readInterval", readInterval);
                    editor1.commit();
                    SharedPreferences sppp = getActivity().getSharedPreferences("Mark3", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor2 = sppp.edit();
                    editor2.putInt("Mark", mark);
                    editor2.commit();


                    mPopWindow.dismiss();
                    tv_course.setText(orgName);
                    lv_course.refresh();
                    requestData();
                    //    readintervalData(adId);
                }
            }
        });
    }

//    //进入课程超市时界面前调一下接口
//    public void readintervalData(String adId) {
//
//        OkGo.get(AppInterfaceConfig.BASE_URL + "sys/config/query/" + adId)     // 请求方式和请求url
//                .tag(this)                       // 请求的 tag, 主要用于取消对应的请求
//                .execute(new StringCallback() {
//                    @Override
//                    public void onSuccess(String result, Call call, Response response) {
//
//                        ReadIntervalBean readIntervalBean = JSON.parseObject(result, ReadIntervalBean.class);
//
//                        ReadIntervalBean.DataBean data = readIntervalBean.getData();
//                        int readInterval = data.getReadInterval();
//                        //存储一份readInterval文件
//                        SharedPreferences sp = getActivity().getSharedPreferences("readInterval",
//                                Context.MODE_PRIVATE);
//                        SharedPreferences.Editor editor = sp.edit();
//                        editor.putInt("readInterval", readInterval);
//                        editor.commit();
//                    }
//                });
//    }

    public void requestData() {
//        lv_course.refresh();
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();

        //存储一份readInterval文件
        SharedPreferences sp = getActivity().getSharedPreferences("readInterval3",
                Context.MODE_PRIVATE);
        int readInterval = sp.getInt("readInterval", 0);
        //存储一份orgId文件
        SharedPreferences spp = getActivity().getSharedPreferences("orgId6",
                Context.MODE_PRIVATE);
        String orgId = spp.getString("orgId", "");
        if (orgId.equals("")) {
            lv_course.setEmptyView(empty_view);
            lv_course.refreshComplete(0);
            return;
        }
        new Login().getPreJobTrainingandcoursesupermaket(userId, orgId, "", 2, readInterval, firstIndex, pageSize, this, 1);


    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        if (what == 1) {
            CourseSuperBean courseSuperBean = JSON.parseObject(result, CourseSuperBean.class);
            if (courseSuperBean != null) {
                try {
//                    if( courseSuperBean.getRows().size()==0)
//                    {
//                           courseSuperAdatper.clear();
//                           lv_course.setEmptyView(empty_view);
//                           lv_course.refreshComplete(0);
//
//                        return;
//                    }
                    if (courseSuperBean.getRows() != null && courseSuperBean.getRows().size() > 0) {
                        lv_course.setVisibility(View.VISIBLE);
                        if (firstIndex == 1) {
                            courseSuperAdatper.clear();
                            courseSuperAdatper.setDataList(courseSuperBean.getRows());
                        } else {
                            courseSuperAdatper.addAll(courseSuperBean.getRows());
                        }

                        if (courseSuperBean.getRows().size() < pageSize) {
                            lv_course.setNoMore(true);
                        }
                    } else {
                        if (firstIndex == 1) {//第一页
                            lv_course.setEmptyView(empty_view);
                            courseSuperAdatper.clear();
                        } else {
                            lv_course.setNoMore(true);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                lv_course.refreshComplete(courseSuperBean.getRows() == null ? 0 : courseSuperBean.getRows().size());
                lRecyclerViewAdapter1.notifyDataSetChanged();
            }
        } else if (what == 2) {
            CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
            int code = checkBean.getCode();
            String msg = checkBean.getMsg();
            if (code == 0) {

                initcoursesupermaketCheckData();

            }

        } else if (what == 3) {

            CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
            int code = checkBean.getCode();
            String msg = checkBean.getMsg();
            if (code == 0) {
                initcoursesupermaketCheckDateData();//判断是否未完成年月份
            }
        } else if (what == 4) {
            CheckDateBean checkDateBean = JSON.parseObject(result, CheckDateBean.class);
            List<CheckDateBean.RowsBean> rows = checkDateBean.getRows();
            if (rows.size() == 0) {
                if (!CameraCanUseUtils.isCameraCanUse()) {
                    ToastUtil.showShortToast(getActivity(), "请到手机设置界面里找驾运宝允许开启照相");
                    return;
                }
                SharedPreferences spp = getActivity().getSharedPreferences("courseSupermarktcSn",
                        Context.MODE_PRIVATE);
                int tcSn = spp.getInt("tcSn", 0);
                Bundle bundle = new Bundle();
                bundle.putInt("tcsn", tcSn);
                SharedPreferences sp = getActivity().getSharedPreferences("readInterval3",
                        Context.MODE_PRIVATE);
                int readInterval = sp.getInt("readInterval", 0);
                bundle.putInt("readInterval", readInterval);
                //存储一份orgId文件
                SharedPreferences sppp = getActivity().getSharedPreferences("orgId6",
                        Context.MODE_PRIVATE);
                String orgId = sppp.getString("orgId", "");
                int minPer = sppp.getInt("minPer", 0);
                bundle.putString("orgId", orgId);
                bundle.putInt("minPer", minPer);
                bundle.putString("setYm", "");
                startActivity(CourseDetailsActivity.class, bundle);


            } else {
                popWindowDateApt = new PopWindowDateApt(getContext(), rows, R.layout.popwindow_dateitem_layout);
                showPopupWindowDate(rows);//弹出未完成时
            }

        }
        super.onSuccess(result, call, response, what);
    }

    private void showPopupWindowDate(List<CheckDateBean.RowsBean> rows) {

        //设置contentView
        View contentView = LayoutInflater.from(getContext()).inflate(R.layout.popwindowdate_layout, null);
        mPopWindowDate = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        //设置各个控件的点击响应
        LinearLayout view_parent = (LinearLayout) contentView.findViewById(R.id.checkdate_le);
        ListView lv_date = (ListView) contentView.findViewById(R.id.lv_date);
        TextView tv_more = (TextView) contentView.findViewById(R.id.tv_checkdate2);
        TextView tv_back = (TextView) contentView.findViewById(R.id.tv_checkdate4);
        tv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPopWindowDate.dismiss();
            }
        });
        TextView tv_nocheckdate = (TextView) contentView.findViewById(R.id.tv_checkdate3);

        tv_nocheckdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (!CameraCanUseUtils.isCameraCanUse()) {
                    ToastUtil.showShortToast(getActivity(), "请到手机设置界面里找驾运宝允许开启照相");
                    return;
                }
                showLoadingDialog("正在加载");
                SharedPreferences spp = getActivity().getSharedPreferences("courseSupermarktcSn",
                        Context.MODE_PRIVATE);
                int tcSn = spp.getInt("tcSn", 0);
                Bundle bundle = new Bundle();
                bundle.putInt("tcsn", tcSn);
                SharedPreferences sp = getActivity().getSharedPreferences("readInterval3",
                        Context.MODE_PRIVATE);
                int readInterval = sp.getInt("readInterval", 0);
                bundle.putInt("readInterval", readInterval);
                //存储一份orgId文件
                SharedPreferences sppp = getActivity().getSharedPreferences("orgId6",
                        Context.MODE_PRIVATE);
                String orgId = sppp.getString("orgId", "");
                int minPer = sppp.getInt("minPer", 0);
                bundle.putString("orgId", orgId);
                bundle.putInt("minPer", minPer);
                bundle.putString("setYm", "");
                startActivity(CourseDetailsActivity.class, bundle);
                mPopWindowDate.dismiss();
            }
        });
        mPopWindowDate.showAtLocation(view_parent, Gravity.CENTER, 0, 0);
        if (rows.size() >= 3) {
            View listItem = popWindowDateApt.getView(0, null, lv_date);
            listItem.measure(0, 0);
            int totalHei = (listItem.getMeasuredHeight() + lv_date.getDividerHeight()) * 3;
            lv_date.getLayoutParams().height = totalHei;
            lv_date.setAdapter(popWindowDateApt);
            tv_more.setVisibility(View.VISIBLE);
        } else {
            lv_date.setAdapter(popWindowDateApt);
            tv_more.setVisibility(View.INVISIBLE);
        }

        lv_date.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                showLoadingDialog("正在加载");
                String setYm = popWindowDateApt.getItem(position).getSetYm();
                //存储一份readInterval文件
                SharedPreferences spp = getActivity().getSharedPreferences("courseSupermarktcSn",
                        Context.MODE_PRIVATE);
                int tcSn = spp.getInt("tcSn", 0);
                Bundle bundle = new Bundle();
                bundle.putInt("tcsn", tcSn);
                SharedPreferences sp = getActivity().getSharedPreferences("readInterval3",
                        Context.MODE_PRIVATE);
                int readInterval = sp.getInt("readInterval", 0);
                bundle.putInt("readInterval", readInterval);
                //存储一份orgId文件
                SharedPreferences sppp = getActivity().getSharedPreferences("orgId6",
                        Context.MODE_PRIVATE);
                String orgId = sppp.getString("orgId", "");
                int minPer = sppp.getInt("minPer", 0);
                bundle.putString("orgId", orgId);
                bundle.putInt("minPer", minPer);
                bundle.putString("setYm", setYm);
                startActivity(CourseDetailsActivity.class, bundle);
                mPopWindowDate.dismiss();

            }
        });

    }

    private void initcoursesupermaketCheckDateData() {

        //存储一份orgId文件
        SharedPreferences spp = getActivity().getSharedPreferences("orgId6",
                Context.MODE_PRIVATE);
        String orgId = spp.getString("orgId", "");
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        new Login().getcoursesupermaketCheckDate(userId, orgId, this, 4);

    }

    @Override
    public void onError(String result, Call call, Response response, int what) {

        if (what == 2) {
            CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
            int code = checkBean.getCode();
            if (code == 2813) {
                String msg = checkBean.getMsg();
                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(getContext());
                builder1.setMessage(msg);
                builder1.setTitle("提示:");
                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        ;
                        //设置你的操作事项
                    }
                });
                builder1.create().show();

            }
        } else if (what == 3) {

            CheckBean checkBean = JSON.parseObject(result, CheckBean.class);
            int code = checkBean.getCode();
            if (code == 1812) {
                String msg = checkBean.getMsg();
                TiShiDialog.Builder builder1 = new TiShiDialog.Builder(getContext());
                builder1.setMessage(msg);
                builder1.setTitle("提示:");
                builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        ;
                        //设置你的操作事项
                    }
                });
                builder1.create().show();
            }
        }

        super.onError(result, call, response, what);
    }


    @Override
    public void onUserVisible() {
        lv_course.refresh();
        requestData();

    }

    private void initUi() {
        LinearLayoutManager ms = new LinearLayoutManager(getActivity());
        ms.setOrientation(LinearLayoutManager.VERTICAL);
        lv_course.setLayoutManager(ms);
        courseSuperAdatper = new CourseSuperAdatper(getContext());
        lRecyclerViewAdapter1 = new LRecyclerViewAdapter(courseSuperAdatper);
        lv_course.setAdapter(lRecyclerViewAdapter1);

        lv_course.setFooterViewColor(R.color.colorAccent, R.color.dark, android.R.color.white);
        lv_course.setFooterViewHint("拼命加载中", "已经全部为你呈现了", "网络不给力啊，点击再试一次吧");
        lv_course.setOnRefreshListener(new OnRefreshListener() {

            @Override
            public void onRefresh() {
                firstIndex = 1;
                requestData();
            }
        });

        lv_course.setOnLoadMoreListener(new OnLoadMoreListener() {

            @Override
            public void onLoadMore() {

                firstIndex += pageSize;
                requestData();
            }
        });
        empty_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                lv_course.refresh();
            }
        });

        lRecyclerViewAdapter1.setOnItemClickListener(new com.github.jdsjlzx.interfaces.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (Utils.isFastDoubleClick()) {
                    return;
                }

                try {

                    SharedPreferences sp1 = getActivity().getSharedPreferences("Mark3", Context.MODE_PRIVATE);
                    int mark = sp1.getInt("Mark", 1);
                    if (mark == 0) {
                        TiShiDialog.Builder builder1 = new TiShiDialog.Builder(getActivity());
                        builder1.setMessage("您已被企业管理员禁用,请联系企业管理员");
                        builder1.setTitle("提示:");
                        builder1.setPositiveButton("我知道", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                //设置你的操作事项
                            }
                        });
                        builder1.create().show();
                        return;
                    }

                    //校验是否学过课程
                    int tcSn = courseSuperAdatper.getDataList().get(position).getTcSn();
                    //存储一份tcSn文件
                    SharedPreferences sp = getActivity().getSharedPreferences("courseSupermarktcSn",
                            Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putInt("tcSn", tcSn);
                    editor.commit();

                    //     initspeciacoursesupermaketCheckData();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        lv_course.refresh();

    }

//    //校验指定学习是否学过
//    private void initspeciacoursesupermaketCheckData() {
//        LoginUserBean userInfo = UserManger.getUserInfo();
//        LoginUserBean.DataBean data = userInfo.getData();
//        if(data==null)
//        {
//            return;
//        }
//        String userId = data.getUserId();
//        //存储一份orgId文件
//        SharedPreferences sp = getActivity().getSharedPreferences("orgId6",
//                Context.MODE_PRIVATE);
//        String orgId = sp.getString("orgId", "");
//        new Login().getlearncoursesupermaketCheck(userId,orgId, this, 2);
//    }

    //校验课程超市课程是否学过
    private void initcoursesupermaketCheckData() {
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        if (data == null) {
            return;
        }
        String userId = data.getUserId();
        //存储一份readInterval文件
        SharedPreferences sp = getActivity().getSharedPreferences("readInterval3",
                Context.MODE_PRIVATE);
        int readInterval = sp.getInt("readInterval", 0);
        //存储一份readInterval文件
        SharedPreferences spp = getActivity().getSharedPreferences("courseSupermarktcSn",
                Context.MODE_PRIVATE);
        int tcSn = spp.getInt("tcSn", 0);
        //存储一份orgId文件
        SharedPreferences sppp = getActivity().getSharedPreferences("orgId6",
                Context.MODE_PRIVATE);
        String orgId = sppp.getString("orgId", "");
//        dialog = CustomProgressDialog.show(getContext(), "", true, null);
        new Login().getPreJobTrainingandcoursesupermaketCheck(userId, orgId, tcSn, readInterval, this, 3);

    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        return false;
    }
}
